from bisect import bisect_right
from random import randrange
from typing import *


class Solution:

    def __init__(self, w: List[int]):
        self.c = 0
        self.h = dict()
        self.p = []
        for i, num in enumerate(w):
            self.p.append(self.c)
            self.h[self.c] = i
            self.c += num

    def pickIndex(self) -> int:
        rdm = randrange(self.c)
        id = bisect_right(self.p, rdm) - 1
        return self.h[self.p[id]]